package NG::Gen::Users::Chat;
use strict;
use warnings;
use utf8;

#use NG::Gen::Users::Constants;

sub chat_after_create {
	my $self = shift;
	my $res;
	my $cnt = 0;
	for(;;) {
		$res = $self->{parent}{app}->chat_query->send_message({
			cmd => "reg",
			userlogin => $self->login,
			userpass => $self->chat_pass,
			tmp => 1,
			chanel => "guest",
		});
		unless($res){
			$self->{parent}{app}->logger("Cannot create chat user");
			return {error=>500,text => "not connect to chat server"};
		}
		if($res->{error}){
			if($res->{error} == 409){
				$self->login($self->login.(++$cnt));
			}else{
				return $res;
			}
		}else{
			$self->setting->chat($self->{parent}{user_config}{chat}{setting});
			return undef;
		}
	}
}
sub chat_after_login {
	my $self = shift;
	my $res = $self->{parent}{app}->chat_query->send_message({
		cmd => "chpass",
		userlogin => $self->login,
		userpass => $self->chat_pass,
	});
}
sub chat_after_validate {
	my $self = shift;
	my $old_login = shift;
	my $res = $self->{parent}{app}->chat_query->send_message({
		cmd => "chlog",
		userlogin => $old_login,
		newlogin => $self->login,
		chanel => "main",
	});
}
sub chat_before_remove {
	my $self = shift;
}
1;
